package com.dg.river.core.util;

import android.app.Activity;

import com.dg.river.core.util.glide.GlideEngine;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;

/**
 * Created by hy on 2018/11/13
 * Description : 相册选择工具类
 */
public class PictureSelectorUtils {

    private static PictureSelectorUtils pictureSelectorUtils;

    public static PictureSelectorUtils getInstance() {
        if (pictureSelectorUtils == null) {
            synchronized (PictureSelectorUtils.class) {
                pictureSelectorUtils = new PictureSelectorUtils();
            }
        }
        return pictureSelectorUtils;
    }

    /**
     * 打开相册
     *
     * @param activity     activity对象
     * @param maxSelectNum 最大可选择图片数量
     */
    public void openAlbum(Activity activity, int maxSelectNum) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .maxSelectNum(maxSelectNum)
                .imageSpanCount(3)
                .isCamera(true)
                .compress(true)
                .compressSavePath(Utils.getZipPath())
                .forResult(PictureConfig.CHOOSE_REQUEST);
    }

    /**
     * 打开相册 只有相册
     *
     * @param activity     activity对象
     * @param maxSelectNum 最大可选择图片数量
     */
    public void openAlbum(Activity activity, int maxSelectNum, int RequestCode) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .imageEngine(GlideEngine.createGlideEngine())
                .maxSelectNum(maxSelectNum)
                .imageSpanCount(3)
                .isCamera(true)
                .isCompress(false)
                .compressSavePath(Utils.getZipPath())
                .withAspectRatio(1, 1)// int 裁剪比例 如16:9 3:2 3:4 1:1 可自定义
                .forResult(RequestCode);
    }

    /**
     * 打开相册
     *
     * @param activity     activity对象
     * @param maxSelectNum 最大可选择图片数量
     */
    public void openAlbum(Activity activity, int maxSelectNum, boolean cut, int RequestCode) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())
                .maxSelectNum(maxSelectNum)
                .imageSpanCount(3)
                .isCamera(true)
                .compress(true)
                .enableCrop(cut)
                .compressSavePath(Utils.getZipPath())
                .forResult(RequestCode);
    }

    /**
     * 打开相机
     *
     * @param activity     activity对象
     */
    public void openCamera(Activity activity, int maxSelectNum, int RequestCode) {
        PictureSelector.create(activity)
                .openCamera(PictureMimeType.ofImage())
                .loadImageEngine(GlideEngine.createGlideEngine())
                .maxSelectNum(maxSelectNum)
                .forResult(RequestCode);
    }
}
